package Test.stream流测试;

import Test.Test02.Student;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;

/**
 * @Author kirito
 * @Date 2023/12/13 19:01
 * @PackageName:Test.stream流测试
 * @ClassName: a
 * @Description:
 * @Version 1.0
 */
public class StreamDemo3 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        Collections.addAll(list, "张三丰", "张无忌", "张三", "李四", "李明", "张强");

        // 合并流
        Stream<String> s1 = list.stream().filter(s -> s.startsWith("张"));
        Stream<String> s2 = Stream.of("java1", "java2");
        // public static <T> Stream<T> concat(Stream<? extends T> a, Stream<? extends T> b)
        Stream<String> s3 = Stream.concat(s1, s2);
        //s3.forEach(System.out::println);
        // 去重后输出
        s3.distinct().forEach(System.out::println);

        // distinct 依赖 hasCode 和 equals 方法
        ArrayList<Student> students = new ArrayList<>();
        Collections.addAll(students, new Student("张无忌"), new Student("张无忌"), new Student("张三丰"), new Student("张三丰"), new Student("李有田"));
        students.stream().distinct().forEach(System.out::println);
        // Student{name='张无忌'}, Student{name='张三丰'}Student{name='李有田'}
    }
}


